<template>
  <div>
    <el-dialog
      title="新建采购入库单"
      :visible.sync="visible"
      :modal-append-to-body="false"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      @close="closeDialog"
      
      width="2000px"
      fullscreen
    >
      <div class="warn">
        <p>
          <strong>说明:</strong>
          <br />标记*的必须录入数据的字段
          <br />
        </p>
      </div>
      <div class="form"></div>
      <el-form
        ref="submit"
        :model="submit"
        label-position="left"
        label-width="105px"
        size="mini"
        inline
      >
        <el-form-item label="单号" label-width="50px">
          <el-input v-model="submit.ref" readonly placeholder="提交后自动生成"></el-input>
        </el-form-item>
        <el-form-item label="*业务日期" label-width="80px">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="submit.dealdate"
            value-format="yyyy-MM-dd"
            style="width: 100%;"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="*供应商" label-width="70px">
          <el-input v-model="submit.suppliername" style="width:200px;" readonly></el-input>
        </el-form-item>
        <br />
        <el-form-item label="*入库仓库" label-width="75px">
          <el-select v-model="submit.storeid" placeholder="请选择分类">
            <el-option v-for="item in storeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="*业务员" label-width="68px">
          <el-input v-model="submit.bizusername" style="width:150px;"></el-input>
          <el-popover placement="right" width="300" v-model="UserListApp.visible">
            <div style="width:300px">
              <el-table
                border
                :data="Lists.userList"
                @row-click="selectUser"
                :stripe="true"
                :header-cell-style="{background:'#e3e5e9',color:'#606266'}"
                :row-style="{height:'5px'}"
                :cell-style="{padding:'5px 0'}"
                tooltip-effect="light"
                highlight-current-row
                style="width: 100%;"
                height="300px"
              >
                <el-table-column prop="name" label="姓名"></el-table-column>
              </el-table>
              <div style="width:100px;background:red;margin:3px auto;">
                <el-button type="primary" @click="SureSelectUser">确定选择业务员</el-button>
              </div>
            </div>
            <el-button slot="reference" @click="UserListApp.visible=true">选择</el-button>
          </el-popover>
        </el-form-item>
        <br />
        <el-form-item label="付款方式" label-width="68px">
          <el-input v-model="submit.paymenttype" style="width:150px;" readonly></el-input>
        </el-form-item>
        <el-form-item label="备注" label-width="40px">
          <el-input v-model="submit.memo" style="width:700px;"></el-input>
        </el-form-item>
      </el-form>
      <div>
        <el-table
          border
          :data="App_Bill_Detail_List.list"
          size="mini"
          :row-style="{height:'5px'}"
          :cell-style="{padding:'5px 0'}"
        >
          <el-table-column  label="序号" width="50">
            <template slot-scope="scope">
              <span>{{scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="code" fixed label="商品编码" width="250"></el-table-column>
          <el-table-column label="商品名称" prop="name" width="200"></el-table-column>
          <el-table-column show-overflow-tooltip prop="spec" label="规格型号" width="250"></el-table-column>
          <el-table-column show-overflow-tooltip prop="count" label="入库数量" width="95"></el-table-column>
          <el-table-column show-overflow-tooltip prop="unitname" label="单位" width="125"></el-table-column>
          <el-table-column prop="price" label="采购单价" width="95"></el-table-column>
          <el-table-column prop="money" label="采购金额" width="95"></el-table-column>
          <el-table-column prop="taxrate" label="税率（%）" width="95"></el-table-column>
          <el-table-column prop="tax" label="税金" width="95"></el-table-column>
          <el-table-column prop="moneywithtax" label="价税合计" width="95"></el-table-column>
          <el-table-column prop="memo" show-overflow-tooltip label="备注" width="95"></el-table-column>
        </el-table>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="visible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="Submit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    form: {
      style: Object
    },
    detail_list: {}
  },
  data() {
    return {
      submit: {
        id: "",
        ref: "",
        billstatu: "",
        dealdate: "",
        dealaddress: "",
        suppliserid: "",
        goodsmoney: "",
        tax: "",
        moneyandtax: "",
        paymenttype: "",
        memo: "",
        bizusername: "",
        orgname: "",
        contact: "",
        suppliername: "",
        inputusername: "",
        datecreated: "",
        confirmusername: "",
        confirmdate: "",
        phone: ""
      },
      storeList: [],
      visible: true,
      Lists: {
        supplierList: [],
        orangeList: [],
        userList: []
      },
      TempApp: {
        supplierTempRow: {}
      },
      SupplierListApp: {
        visible: false,
        datas: {}
      },
      UserListApp: {
        visible: false
      },
      App_Bill_Detail_List: {
        list: [],
        SelectRow: {}
      },
      miniApp_Good_List: {
        visible: false
      }
    };
  },
  methods: {
    Check() {
      if (
        this.submit.dealdate == null ||
        this.submit.dealdate == "" ||
        this.submit.suppliername == null ||
        this.submit.suppliername == "" ||
        this.submit.orgname == null ||
        this.submit.orgname == "" ||
        this.submit.bizusername == null ||
        this.submit.bizusername == "" ||
        this.App_Bill_Detail_List.list == null ||
        this.App_Bill_Detail_List.list.length == 0
      ) {
        this.$message.error("请录入完整的数据！");
        return false;
      }
      return true;
    },
    Submit() {
      var day2 = new Date();
      day2.setTime(day2.getTime());
      this.submit.ref =
        "PW" +
        day2.getFullYear() +
        (day2.getMonth() + 1) +
        day2.getDate() +
        day2.getHours() +
        day2.getMinutes() +
        day2.getSeconds();
      this.submit.statu = "待入库";
      this.$http
        .get("store/selectOne", {
          params: {
            id: this.submit.storeid
          }
        })
        .then(response => {
          this.submit.storename = response.data.name;
          this.$http
            .post("purchaseenterlist/insert", this.submit)
            .then(response => {
              if (response.data == "success") {
                this.form.billstatu = "申请入库中";
                this.$http.post("/order/updata", this.form).then(response => {
                  if (response.data == "success") {
                    if (response.data == "success") {
                      this.$message({
                        message: "审核完成",
                        type: "success"
                      });
                      this.NeedRefresh();
                      this.visible = false;
                    }
                  }
                });
              }
            });
        });

      window.console.log("form", this.form);
      window.console.log("submit", this.submit);
    },
    closeDialog() {
      window.console.log("dfialog-close");
      this.$emit("dialog-close");
    },
    NeedRefresh() {
      this.$emit("refresh");
    },
    selectUser(Row) {
      this.submit.bizusername = Row.name;
    },

    GetLists() {
      this.$http.get("/user/list").then(response => {
        this.Lists.userList = response.data;
      });
      this.$http.post("/good/someGoodList", {}).then(response => {
        this.miniApp_Good_List.list = response.data;
      });
      this.$http.get("/supplier/list").then(response => {
        this.Lists.supplierList = response.data;
      });
      this.$http.get("/store/list").then(response => {
        this.storeList = response.data;
      });
    },
    SureSelectUser() {
      this.UserListApp.visible = false;
    }
  },
  created() {
    // this.$http
    //   .post("orangetree/organename", { id: this.form.orangeid })
    //   .then(response => {
    //     this.submit.orangename = response.data;
    //   });
    // this.submit = JSON.parse(JSON.stringify(this.form));
    this.GetLists();
    this.submit.suppliername = this.form.suppliername;
    this.submit.paymenttype = this.form.paymenttype;
    this.submit.tax = this.form.tax;
    this.submit.goodsmoney = this.form.goodsmoney;
    this.submit.moneyandtax = this.form.moneyandtax;
    this.submit.orderid = this.form.id;
    this.$http
      .post("orderdetail/somelist", { orderid: this.form.id })
      .then(response => {
        this.App_Bill_Detail_List.list = response.data;
      });
  }
};
</script>

<style>
.form {
  margin-top: 20px;
}
</style>